﻿using MassTransit;
using SharedMessages.Messages;

namespace ShippingService.Consumers
{
    public class OrderPlacedConsumer : IConsumer<OrderPlaced>
    {
        public Task Consume(ConsumeContext<OrderPlaced> context)
        {
            if (context.Message.Quantity <= 0)
            {
                Console.WriteLine($"Rejected order with Id:{context.Message.OrderId} time:{DateTime.Now}");
                throw new Exception("Invalid quantity, rejectiong the message.");
            }
            Console.WriteLine($"Processed order with ID:{context.Message.OrderId}");
            return Task.CompletedTask;
        }
    }
}
